package com.wthink.newMain.settings.config.inner.reboot

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wthink.hzgj.data.Result
import com.wthink.hzgj.service.DevService
import com.wthink.newMain.data.FireData
import com.wthink.newMain.data.SerialData
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.math.BigDecimal

class RebootViewmodel : ViewModel(){

    var mix = 0L

    //  val timeItems = arrayListOf( "永不","3小时", "6小时", "9小时", "12小时", "18小时", "24小时")

    val fireData = MutableLiveData<FireData>()

    fun start(success: (firedata: FireData) -> Unit) {
        viewModelScope.launch(Dispatchers.IO) {
            val ret = DevService.getFireConfig()
            if (ret is Result.Success) {
                fireData.postValue(ret.data)
                success(ret.data)
            }
        }
    }

    fun config(type:String,delayTime:String,startTime:String,endTime:String,backLight:String) {
        viewModelScope.launch(Dispatchers.IO) {
            val ret = DevService.setFireConfig(type,delayTime,startTime,endTime,backLight)
            if (ret is Result.Success) {

            }
        }
    }

    fun getTime(success: (notime: BigDecimal) -> Unit){
        viewModelScope.launch(Dispatchers.IO) {
            val ret = DevService.getTime()
            if (ret is Result.Success) {
                val data = ret.data * 1000
                mix = data - System.currentTimeMillis() + 1000 * 60 * 60 * 8
                val nowTime: BigDecimal =
                    BigDecimal(mix).add(BigDecimal(System.currentTimeMillis()))
                success(nowTime)
            }
        }
    }
}